#include"searcher.hpp"
#include"cpp-httplib/httplib.h"

const std::string root_path="./wwwroot";
const std::string input="./data/out.bin";
int main()
{
    us_searcher::Searcher search;
    httplib::Server ser;
    ser.set_base_dir(root_path.c_str());
    search.InitSearcher(input);

    ser.Get("/s",[&search](const httplib::Request& req,httplib::Response& res){

        if(!req.has_param("word")) //如果没有word参数，那么就给用户提示
        {
            res.set_content("请输入你需要搜索的关键字","text/plain; charset=utf-8");
            return ;
        }
        std::string word = req.get_param_value("word"); 
        std::cout<<"用户搜索的内容为:"<<word<<std::endl;
        std::string json_string;
        search.Search(word,&json_string);

        res.set_content(json_string,"application/json");

    });

    ser.listen("0.0.0.0",8081);
    return 0;
}